package net.zjitc.dao;

import net.zjitc.pojo.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookDao {
    @Select("select * from books;")
    public List<Book> findAll();

    @Insert("insert into books (name,isbn,author,price,press) values (#{name},#{isbn},#{author},#{price},#{press});")
    int insert(Book book);

    @Delete("delete from books where id = #{id};")
    int delete(int id);

    @Select("select * from books where id = #{id};")
    public Book findById(int id);

    @Update("update books set name = #{name}, " +
            "isbn = #{isbn}, " +
            "author = #{author}, " +
            "price = #{price}, " +
            "press = #{press} " +
            "where id=#{id};")
    int update(Book book);
}
